package com.vitabuybuy.tv.ui.home.bidd.adapter

import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.library.common.util.DateUtil
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ItemBiddingZoneBinding
import com.vitabuybuy.tv.dto.BiddingListDto
import com.library.common.base.BindRecycAdapter

class BiddingZoneAdapter : BindRecycAdapter<ItemBiddingZoneBinding, BiddingListDto>() {
    var currentId = 0
    override fun onBindViewHolder(
        mBinding: ItemBiddingZoneBinding,
        itemData: BiddingListDto,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        mBinding.currentId = currentId
        mBinding.itemData = itemData
        if (itemData.remainingTime == 0L) {
            mBinding.tvBiddingTime.text = mContext.getString(R.string.has_over)
            mBinding.btnMakeAnAppointment.apply {
                text = mContext.getString(R.string.has_over)
                setNormalSolid(ContextCompat.getColor(mContext, R.color.text_e0e0e0))
            }
        } else {
            mBinding.btnMakeAnAppointment.text = if (currentId == 0) {
                mContext.getString(R.string.join_bidding)
            } else {
                mContext.getString(R.string.make_an_appointment)
            }
            mBinding.tvBiddingTime.text = if (currentId == 0) {
                String.format(
                    mContext.getString(R.string.remaining_time),
                    DateUtil.formatSeconds(itemData.remainingTime)
                )
            } else {
                String.format(
                    mContext.getString(R.string.bidding_time),
                    itemData.startTime
                )
            }
        }
    }

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_bidding_zone
    }
}
